

import sys

class Solution(object):
    def minSubArrayLen(self, s, nums):
        """
        :type s: int
        :type nums: List[int]
        :rtype: int
        """
        begin = 0
        minLength = sys.maxsize
        maxSorFar = 0 # sum nearest below s
        for end in range(len(nums)):
            maxSorFar+=nums[end]
            if maxSorFar>=s:
                length = end-begin+1
                minLength = min(minLength, length)
                for b in range(begin, end+1):
                    maxSorFar-=nums[b]
                    if maxSorFar>=s:
                        length = end-b
                        minLength = min(minLength, length)
                    else:
                        begin = b+1
                        break
        return minLength if minLength!=sys.maxsize else 0
        
print(Solution().minSubArrayLen(7, [2,3,1,2,4,3]))